package org.jeecg.modules.home;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.userFormula.entity.UserFormulaDetail;
import org.jeecg.modules.util.HttpClientUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
@Api(tags = "首页")
@RestController
@RequestMapping("/home/home")
@Slf4j
public class HomeController {
    @Value("${zfservice.url}")
    private String zfserviceUrl;

    @AutoLog(value = "首页-统计")
    @ApiOperation(value = "首页-统计", notes = "首页-统计")
    @GetMapping(value = "/dataStat")
    public Result<Object> dataStat() {
        try {
            String url = zfserviceUrl + "/analysis/data_stat";
            JSONObject object = HttpClientUtil.sendGet(url,null);
            if (object == null) {
                return Result.error("获取数据失败");
            }
            if (object.get("code") != null && Integer.parseInt(object.get("code").toString()) == 0) {
                return Result.OK(object.get("data"));
            } else {
                if (object.containsKey("message") && object.get("message") != null) {
                    return Result.error(object.get("message").toString());
                } else {
                    return Result.error("获取数据失败");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
            return Result.error("获取数据失败，请联系管理员");
        }
    }
}
